package org.csu.onlineedubackend.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.csu.onlineedubackend.entity.VideoStudentCourseProgress;

import java.util.List;
import java.util.Map;

@Mapper
public interface VideoStudentCourseProgressMapper extends BaseMapper<VideoStudentCourseProgress> {
    
    /**
     * 根据学生ID和课时ID查询观看进度
     * @param studentId 学生ID
     * @param lessonId 课时ID
     * @return 视频观看进度记录
     */
    @Select("SELECT * FROM video_student_course_progress WHERE student_id = #{studentId} AND lesson_id = #{lessonId}")
    VideoStudentCourseProgress selectByStudentAndLesson(Integer studentId, Integer lessonId);

    // 获取学生日活量
    @Select("""
    SELECT DATE_FORMAT(last_watched, '%Y-%m-%d') AS day,
           COUNT(DISTINCT student_id) AS activeCount
    FROM video_student_course_progress
    WHERE last_watched IS NOT NULL
    GROUP BY day
    ORDER BY day
""")
    List<Map<String, Object>> getDailyActiveStudents();

} 